﻿<%@ codepage=65001%><% 'UTF-8%>

<%'检查是否登录%>
 
<%'注册账号 处理%>
<!--#include file="../Include/Common.All.asp"-->
<!--#include file="../Include/Conn.asp"-->
<% call OpenConn%>

<!--#include file="../Include/Common.Security.asp"-->
<!--#include file="../Include/MD5.asp"-->
<!--#include file="../Include/JSON_2.0.2.asp"-->
<!--#include file="../Include/CardMake.asp"-->



<%

'定义json对象
Dim loginObj
Set loginObj = jsObject()

	dim seccode,UserName,UserPassword ,UserType,roletype
	seccode=ReplaceBadChar(Trim(request.Form("seccode")))'校验码
	UserName=ReplaceBadChar(Trim(request.Form("account")))'用户名
	UserPassword=ReplaceBadChar(Trim(request.Form("pwd1")))'登录密码
	UserType=ReplaceBadChar(Trim(request.Form("passport")))'用户类别 企业 个人
	roletype="0" '初始用户的权限 缺省为0 ，管理员-1 受理机构用户-2 企业用户-3

	dim NickName,Answer,Question ,Email
	NickName=ReplaceBadChar(Trim(request.Form("nick")))'昵称
	Answer=ReplaceBadChar(Trim(request.Form("answer")))'问题答案
	Question=ReplaceBadChar(Trim(request.Form("question")))'问题
	Email=ReplaceBadChar(Trim(request.Form("email")))'邮箱地址
	
	dim Country,Province,Address ,ZipCode
	Country=ReplaceBadChar(Trim(request.Form("country")))'国家
	Province=ReplaceBadChar(Trim(request.Form("province")))'省份
	Address=ReplaceBadChar(Trim(request.Form("address")))'地址
	ZipCode=ReplaceBadChar(Trim(request.Form("postcode")))'邮编

	dim TrueName,Sex,IDCard ,mobile ,telnum
	TrueName=ReplaceBadChar(Trim(request.Form("contactor")))''真实姓名：
	Sex=ReplaceBadChar(Trim(request.Form("gender")))''性别
	IDCard=ReplaceBadChar(Trim(request.Form("idnumber")))''证件号码：
	Mobile=ReplaceBadChar(Trim(request.Form("mobile")))''手机号码：
	telnum=ReplaceBadChar(Trim(request.Form("telnum")))''手机号码：

	dim enterprise,industry,admin_name ,admin_gender ,admin_telnum ,admin_mobile '''企业基本资料
	enterprise=ReplaceBadChar(Trim(request.Form("enterprise")))''企业名称：
	industry=ReplaceBadChar(Trim(request.Form("industry")))''所属行业：
	admin_name=ReplaceBadChar(Trim(request.Form("admin_name")))''联系人姓名
	admin_gender=ReplaceBadChar(Trim(request.Form("admin_gender")))''联系人性别
	admin_telnum=ReplaceBadChar(Trim(request.Form("admin_telnum")))''联系人电话
	admin_mobile=ReplaceBadChar(Trim(request.Form("admin_mobile")))''联系人手机号码
	
	
	'UserName="fashioncat1"
	'UserPassword="fashioncat1"
	'seccode=Session("VerifyCode")
	'MD5处理密
	UserPassword = MD5(UserPassword, 16)


	Dim isCheck'检查标志位 
	isCheck=true
  ''Response.Write "+++++++++++++"&  Card_Make("batch_","1",Conn)
   

if (true=isCheck and  Session("VerifyCode") <> seccode) then
	loginObj("msg") ="&#x6821;&#x9A8C;&#x7801;&#x9519;&#x8BEF;&#xFF0C;&#x6CE8;&#x518C;&#x5931;&#x8D25;&#xFF01;"   ''"校验码错误，注册失败！"
	loginObj("success") = 0'false
	isCheck=false
elseif (true=isCheck and regCheckUserName(UserName)) then'检查用户名是否冲突
	loginObj("msg") = "&#x5BF9;&#x4E0D;&#x8D77;&#xFF0C;&#x8BE5;&#x7528;&#x6237;&#x540D;&#x5DF2;&#x7ECF;&#x88AB;&#x6CE8;&#x518C;&#xFF01;"''"对不起，该用户名已经被注册！"
	loginObj("success") = 0'false
	isCheck=false
elseif (true=isCheck ) then''校验用户名密码
	If (UserName <> "" and UserPassword <> "" ) Then
		dim UserID
		UserID = PE_CLng(Conn.Execute("select ISNULL(MAX(UserID), 0) from PE_User")(0)) + 1
		Dim rsObj,strSql
		set rsObj=Server.CreateObject("ADODB.Recordset")
		strSql = "Select  * from PE_User"
		rsObj.Open strSql, Conn, 1, 3
		rsObj.AddNew
		rsObj("UserID") = UserID
		rsObj("UserName") = UserName
		rsObj("UserPassword") = UserPassword
		rsObj("RegTime") = Now()
		rsObj("UserSetting") = UserType''备注

		if ("personal"=UserType) Then'受理机构用户注册	
			roletype="-2"		''受理机构用户角色
			rsObj("UserType") = 1''受理机构用户类型
			rsObj("TrueName") = TrueName'真实姓名：
			rsObj("Sex") = Sex'性别
			rsObj("IDCard") = IDCard'证件号码
			rsObj("Mobile") = Mobile'手机号码			
			rsObj("OfficePhone") = telnum'联系人电话			
		end if
		if ("ent"=UserType) Then'企业用户注册			
			roletype="-3"		''企业用户角色
			rsObj("UserType") = 2''企业用户类型	
			rsObj("Company") = enterprise'企业名称：
			rsObj("Vocation") = industry'所属行业：
			rsObj("TrueName") = admin_name'联系人姓名
			rsObj("Sex") = admin_gender'联系人性别
			rsObj("OfficePhone") = admin_telnum'联系人电话
			rsObj("mobile") = admin_mobile'联系人手机号码			
		end if		
		
		rsObj("NickName") = NickName'昵称
		rsObj("Answer") = Answer'问题答案
		rsObj("Question") = Question'问题
		rsObj("Email") = Email'邮箱地址
		rsObj("Country") = Country'国家
		rsObj("Province") = Province'省份
		rsObj("Address") = Address'地址
		rsObj("ZipCode") = ZipCode'邮编
		
		rsObj.Update
		rsObj.close
		Set rsObj = Nothing
		
		''附加权限 begin''''''''
		Dim  RowCount,RowCount_checkok 
    RowCount = 0
    ''清除权限
 		strSql = "delete from T_USER_ROLE where user_id="&UserID&" "
   	Conn.Execute (strSql), RowCount
   	RowCount_checkok=RowCount_checkok+RowCount
    ''添加权限    
    strSql = "INSERT INTO T_USER_ROLE  (user_id, role_id) VALUES ("&UserID&", "&roletype&") "
    Conn.Execute (strSql), RowCount
    RowCount_checkok=RowCount_checkok+RowCount
    ''附加权限 end''''''''
    
    ''分配缺省会员卡 begin '''''''''
    dim batchcode''批次编码
    batchcode=Card_Make("batch_"&UserName,"1",Conn)
    if ("-1"<>batchcode) then RowCount_checkok=RowCount_checkok+1
  
	  ''flag状态标示 缺省卡2、发卡为1
	  ''zt 状态标示 1开卡有效、0初始 ， 2失效
	  
    ''将刚生成的卡分配至该注册用户
	  strSql = " INSERT INTO HY_KH (cardcode, Hycode, zt, flag) "
	  strSql = strSql & " SELECT cardcode AS cardcode, "&UserID&" AS Hycode, 1 AS zt, 2 AS flag "
	  strSql = strSql & " FROM KH_XX WHERE 1=2 "
	  if (""<>batchcode) then strSql = strSql & " or batchcode = '"&batchcode&"'  "
    Conn.Execute(strSql), RowCount
    RowCount_checkok=RowCount_checkok+RowCount
    
    ''''改变会员卡的状态
		strSql = "Update KH_XX set zt=1  where batchcode='"&batchcode&"'"
		Conn.Execute(strSql), RowCount
		RowCount_checkok=RowCount_checkok+RowCount
		''分配缺省会员卡 end '''''''''	
				 
		if (5<>RowCount_checkok) then
			loginObj("success") = 0'"false"
			loginObj("msg") =  "注册失败，请联系管理员！"
 			loginObj("url") = "welcome.asp"
 		end if
 
		isCheck=false
		Session("UserName")=""
		Session("UserID")=""
		Session("UserName")=UserName
		Session("UserID")=UserID
		loginObj("msg") =  "&#x6CE8;&#x518C;&#x6210;&#x529F;,&#x8DF3;&#x8F6C;&#x4E2D;..." '"注册成功,跳转中..."
		loginObj("success") = 1'"true"
		loginObj("url") = "welcome.asp"
	else
		loginObj("msg") =  "&#x6CE8;&#x518C;&#x5931;&#x8D25;&#xFF0C;&#x8BF7;&#x786E;&#x5B9A;&#x7528;&#x6237;&#x540D;&#x548C;&#x5BC6;&#x7801;&#xFF01;"''"注册失败，请确定用户名和密码！"
		loginObj("success") = 0'"false"
		isCheck=false
		
	End If


  

end if 'Session("VerifyCode")
		'调试信息
		''loginObj("msg") = loginObj("msg")'&"+"&Session("VerifyCode")&"-"&seccode&"-"&UserName&"-"&UserPassword
		'输出json对象
		loginObj.Flush
		'''Response.Write strSql
	call CloseConn




	Sub AddUser(UserName,UserPassword)
		Dim rsObj,strSql
		strSql = "select top 1 * from PE_User"
		Set rsObj = Server.CreateObject("adodb.recordset")
		rsObj.Open strSql, Conn, 1, 3
		rsObj.addnew
		rsObj("UserName") = UserName
		rsObj("UserPassword") = UserPassword
		rsObj("RegTime") = Now()
		rsObj.Update
		rsObj.Close
		Set rsObj = Nothing
	End Sub

''检查用户名 名字冲突返回 True 不允许注册
Function regCheckUserName(UserName)
	regCheckUserName=false      
	dim count_user
	If (trim(UserName) <> ""  ) Then
		count_user = PE_CLng(Conn.Execute("select COUNT(UserID) AS count_user from PE_User WHERE UserName='" & UserName & "'" )(0)) 
		If (0<count_user) Then regCheckUserName = True
	end if 

End Function
	%>
